package com.artqiyi.dollmachine.views.adapter;

import android.support.annotation.Nullable;

import com.artqiyi.dollmachine.R;
import com.artqiyi.dollmachine.model.entity.CoinBuyBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2017/10/30 0030.
 */

public class PayFragmentAdapter extends BaseQuickAdapter<CoinBuyBean, BaseViewHolder>{

    private int mSelectPosition = -1;
    public PayFragmentAdapter(@Nullable List<CoinBuyBean> data) {
        super(R.layout.item_pay_fragment, data);
    }

    public void setSelectPosition(int position) {
        this.mSelectPosition = position;
    }

    @Override
    protected void convert(BaseViewHolder helper, CoinBuyBean item) {
        helper.setText(R.id.tvCoin, item.getCoin());
        helper.setText(R.id.tvMoney, "￥" + item.getMoney());
        helper.setText(R.id.tvAward, setAwardCoin(item.getCoin_award()));

        if (helper.getLayoutPosition() == mSelectPosition) {
            helper.getView(R.id.mainLayout).setBackgroundResource(R.drawable.round_orange_without_solid_bg);
        } else {
            helper.getView(R.id.mainLayout).setBackgroundResource(R.drawable.round_white_bg);
        }
    }

    private String setAwardCoin(int awardCoin) {
        if (awardCoin != 0) return "(" + String.format(mContext.getString(R.string.award_coin), String.valueOf(awardCoin)) + ")";
        else return "";
    }

}
